﻿using System.Windows.Input;
using System.Windows.Controls;
using System.Windows.Interactivity;

namespace Thinktecture.UIAnnotations.Behaviors
{
    public class NumericInputBehavior : TriggerAction<TextBox>
    {
        protected override void Invoke(object parameter)
        {
            var e = parameter as KeyEventArgs;
            if ((e.Key < Key.D0 || e.Key > Key.D9) &&
                (e.Key < Key.NumPad0 || e.Key > Key.NumPad9) &&
                (e.Key != Key.Back && e.Key != Key.Tab && e.Key != Key.Escape))
            {
                e.Handled = true;
            }
        }
    }
}
